import request from '@/utils/request'

// 预约相关API接口

/**
 * 创建预约
 */
export function createAppointment(data) {
  return request({
    url: '/appointment/create',
    method: 'post',
    data
  })
}

/**
 * 取消预约
 */
export function cancelAppointment(id) {
  return request({
    url: `/appointment/cancel/${id}`,
    method: 'put'
  })
}

/**
 * 根据ID查询预约详情
 */
export function getAppointmentById(id) {
  return request({
    url: `/appointment/${id}`,
    method: 'get'
  })
}

/**
 * 获取当前用户的预约列表
 */
export function getMyAppointments() {
  return request({
    url: '/appointment/my',
    method: 'get'
  })
}

/**
 * 获取当前店长的预约列表
 */
export function getStoreManagerAppointments(params) {
  return request({
    url: '/appointment/store-manager',
    method: 'get',
    params
  })
}

/**
 * 分页查询预约记录
 */
export function getAppointmentPage(params) {
  return request({
    url: '/appointment/page',
    method: 'get',
    params
  })
}

/**
 * 获取所有店长的排班时间表
 */
export function getAllStoreManagerSchedules() {
  return request({
    url: '/appointment/schedules',
    method: 'get'
  })
}

/**
 * 根据店长ID获取排班时间表
 */
export function getStoreManagerSchedule(storeManagerId) {
  return request({
    url: `/appointment/schedule/${storeManagerId}`,
    method: 'get'
  })
}

/**
 * 确认预约
 */
export function confirmAppointment(id) {
  return request({
    url: `/appointment/confirm/${id}`,
    method: 'put'
  })
}

/**
 * 完成预约
 */
export function completeAppointment(id) {
  return request({
    url: `/appointment/complete/${id}`,
    method: 'put'
  })
}

/**
 * 获取店长在特定日期的可用时间段
 */
export function getStoreManagerAvailableHours(storeManagerId, appointmentDate) {
  return request({
    url: `/appointment/available-hours/${storeManagerId}/${appointmentDate}`,
    method: 'get'
  })
}

/**
 * 根据日期获取所有有排班的发型师
 */
export function getAvailableStoreManagersByDate(appointmentDate) {
  return request({
    url: `/appointment/available-managers/${appointmentDate}`,
    method: 'get'
  })
}

/**
 * 根据发型师ID获取其未来可用的日期排班
 */
export function getStoreManagerAvailableDates(storeManagerId, days = 7) {
  return request({
    url: `/appointment/available-dates/${storeManagerId}`,
    method: 'get',
    params: { days }
  })
}

/**
 * 获取店长在特定日期的时间段可用性信息（包含剩余名额）
 */
export function getStoreManagerTimeSlotAvailability(storeManagerId, appointmentDate) {
  return request({
    url: `/appointment/time-slot-availability/${storeManagerId}/${appointmentDate}`,
    method: 'get'
  })
}

/**
 * 管理员获取所有用户预约记录（分页）
 */
export function getAdminAppointmentPage(params) {
  return request({
    url: '/appointment/admin/all',
    method: 'get',
    params
  })
} 